#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=210;
int n,sum,f[2][MAXN*MAXN];
struct node
{
	int x,y;
	bool operator<(const node b)const
	{
		return y==b.y?x<b.x:y>b.y;
	}
}a[MAXN];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i].x=read(),a[i].y=read();
	sort(a+1,a+1+n);
	int cur=0;
	memset(f[0],INF,sizeof(f[0]));
	f[0][0]=0;
	for(int i=1;i<=n;++i)
	{
		cur^=1;
		memset(f[cur],INF,sizeof(f[cur]));
		sum+=a[i].x;
		for(int j=0;j<=sum;++j)
		{
			if(j>=a[i].x)f[cur][j]=min(f[cur][j],max(f[cur^1][j-a[i].x],j+a[i].y));
			f[cur][j]=min(f[cur][j],max(f[cur^1][j],sum-j+a[i].y));
		}
	}
	int ans=INF;
	for(int i=0;i<=sum;++i)ans=min(ans,f[cur][i]);
	printf("%d\n",ans);
	return 0;
}
